package com.kedacom.freedomLabel.view.fragment;

import android.databinding.ViewDataBinding;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.RecyclerView;

import com.kedacom.freedomLabel.R;
import com.kedacom.freedomLabel.databinding.ItemIdLayoutBinding;
import com.kedacom.freedomLabel.model.bean.IFirstLetter;
import com.kedacom.lego.adapter.recyclerview.LegoBaseRecyclerViewAdapter;

import java.util.List;

/**
 * @author licheng
 * @since 2020/2/24 15:19
 */
public class IFirstLetterAdapter<T extends IFirstLetter> extends LegoBaseRecyclerViewAdapter<T> {

    public IFirstLetterAdapter(List<T> data) {
        super(R.layout.item_id_layout, data);
    }

    @Override
    public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
        super.onAttachedToRecyclerView(recyclerView);
        ((DefaultItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
    }

    @Override
    protected void onCustomBindItem(ViewDataBinding binding, int position) {
        ItemIdLayoutBinding itemBinding = (ItemIdLayoutBinding) binding;
        T data = getData().get(position);
        itemBinding.itemIdName.setText(data.getItemName());
        if (data.isSelected()) {
            itemBinding.getRoot().setBackgroundColor(Color.DKGRAY);
            itemBinding.itemIdName.setTextColor(Color.WHITE);
        } else {
            itemBinding.getRoot().setBackgroundColor(Color.parseColor("#EFEFEF"));
            itemBinding.itemIdName.setTextColor(Color.BLACK);
        }
    }
}